package models

import (
	"github.com/GoAdminGroup/go-admin/modules/db"
	"github.com/jinzhu/gorm"
)

var (
	Orm *gorm.DB
	err error
)

func Init(c db.Connection) {
	config := c.GetDB("default")
	Orm, err = gorm.Open("mysql", config)

	if err != nil {
		panic("initialize orm failed")
	}
	Orm.LogMode(true)
	Orm = Orm.Debug()
}

type BaseModel interface {
	TableName() string
}

type Pagination struct {
	PageBy    string
	PageSize  int `form:"page_size"`
	PageIndex int `form:"page_index"`
}

type Pager struct {
	// 当前请求条件下的总元素数
	Count int `json:"total_item" example:"100"`
	// 当前请求返回值数据所代表的页码
	Index int `json:"page_index" example:"2"`
	// 当前请求返回值所代表页的页内最大元素数量
	Size int `json:"page_size" example:"20"`
}
